package logic

import (
	"context"

	"github.com/comfygpt-backend-go/common/consts"
	"github.com/comfygpt-backend-go/service/component-api/internal/svc"
	"github.com/comfygpt-backend-go/service/component-api/internal/types"
	"github.com/comfygpt-backend-go/service/component-rpc/component"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteComponentLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteComponentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteComponentLogic {
	return &DeleteComponentLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteComponentLogic) DeleteComponent(req *types.ComponentIdRequest) (resp *types.CommonResp, err error) {
	// 初始化响应
	resp = &types.CommonResp{
		Code:    int64(consts.SUCCESS),
		Message: consts.WrongMessageEn[consts.SUCCESS],
	}

	// 校验参数
	item := &component.ComponentIdRequest{
		Id: req.Id,
	}

	// 创建组件
	_, err = l.svcCtx.ComponentRpc.DeleteComponent(l.ctx, item)
	if err != nil {
		resp.Code = int64(consts.SERVER_WRONG)
		resp.Message = consts.WrongMessageEn[consts.SERVER_WRONG]
		return
	}
	return
}
